from selenium import selenium
import unittest, time, re

class PermConfTest(unittest.TestCase):
    def setUp(self):
        self.verificationErrors = []
        self.selenium = selenium("localhost", 4444, "*firefox", "http://127.0.0.1:8000/")
        self.selenium.start()
    
    def test_drop_down(self):
        sel = self.selenium
        sel.open("/ecuaciones/#")
        sel.type("id_Q", "250")
        sel.type("id_T", "100")
        sel.type("id_R", "500")
        sel.type("id_r", "0.5")
        sel.click("//input[@value='Calcular']")
        for i in range(60):
            try:
                if "" != sel.get_value("id_s"): break
            except: pass
            time.sleep(1)
        else: self.fail("time out")
        self.assertEqual(float(sel.get_value("id_s")), 1.374)
        
    def test_transmisivity(self):
        sel = self.selenium
        sel.open("/ecuaciones/#")
        sel.type("id_Q", "250")
        sel.type("id_R", "500")
        sel.type("id_r", "0.5")
        sel.type("id_s", "1")
        sel.click("//input[@value='Calcular']")
        for i in range(60):
            try:
                if "" != sel.get_value("id_T"): break
            except: pass
            time.sleep(1)
        else: self.fail("time out")
        self.assertEqual(float(sel.get_value("id_T")), 137.425)
    
    def test_observation_radius(self):
        sel = self.selenium
        sel.open("/ecuaciones/#")
        sel.type("id_Q", "250")
        sel.type("id_R", "500")
        sel.type("id_T", "100")
        sel.type("id_s", "1")
        sel.click("//input[@value='Calcular']")
        for i in range(60):
            try:
                if "" != sel.get_value("id_r"): break
            except: pass
            time.sleep(1)
        else: self.fail("time out")
        self.assertEqual(float(sel.get_value("id_r")), 3.281)
        
    def test_flow_rate(self):
        sel = self.selenium
        sel.open("/ecuaciones/#")
        sel.type("id_r", "0.5")
        sel.type("id_R", "500")
        sel.type("id_T", "100")
        sel.type("id_s", "1")
        sel.click("//input[@value='Calcular']")
        for i in range(60):
            try:
                if "" != sel.get_value("id_Q"): break
            except: pass
            time.sleep(1)
        else: self.fail("time out")
        self.assertEqual(float(sel.get_value("id_Q")), 181.917)
        
    def tearDown(self):
        self.selenium.stop()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()
